package com.zpark.servlet_request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @PackageName: com.zpark.servlet_request
 * @ClassName: ServletRequstDemo01
 * @Description:
 * @author: RZS
 * @date: 2023/3/9  14:41
 */
@WebServlet("/sq01.do")
public class ServletRequestDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取请求头信息  获取一个指定头字段的值
        String header = request.getHeader("user-agent");
        System.out.println(header);

        System.out.println("*******************************************************");
        // 获取所有请求头名字，返回一个枚举
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            // 获取每一个请求头的名字
            String name = headerNames.nextElement();
            // 根据请求头名字获取对应的请求头值
            String value = request.getHeader(name);
            System.out.println(name + ": " + value);
        }
        System.out.println("*******************************************************");
        // 获取 Content-Type 头字段的值
        System.out.println(request.getContentType());
        // 获取 Content-Length 头字段的值
        System.out.println(request.getContentLength());
        // 返回请求消息的字符集编码
        System.out.println(request.getCharacterEncoding());


    }
}
